#include <omp.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

void init(double** M, int size)
{
	 for (int i=0;i<size;i++)
	     for (int j=0;j<size;j++)
			M[i][j]=i*size+j;
}

int main(int argc, char *argv[])
{
	const int n = 1000;
  cout<<"Razmern: "<<n<<""<<"\n";
	//ñîçäàíèå ìàòðèö
	double start_time, end_time;

	double** a=new double*[n];
	for(int i=0; i<n;i++)
		a[i]=new double[n];

	double** b=new double*[n];
	for(int i=0; i<n;i++)
		b[i]=new double[n];

	double** c=new double*[n];
	for(int i=0; i<n;i++)
		c[i]=new double[n];

	//èíèöèàëèçàöèÿ
	init(a, n);
	init(b,n);

	int j, k;
	double sum;
	start_time = omp_get_wtime() ;
	#pragma omp parallel for private(j,k,sum) 
	 for(int i=0;i<n;i++){ //îäèí ôîð äëÿ îòäåëüíîãî ïîòîêà
		for(j=0;j<n;j++){
			 sum=0;		
			for(k=0;k<n;k++){
				 sum+=a[i][k]*b[k][j];
				 c[i][j]=sum;
			}
		}
	}	 
 end_time = omp_get_wtime() ;

 cout<<"Parallel multiplication\n";
 cout<<"Time: "<<end_time-start_time<<" seconds"<<"\n";

 for(int i=0; i<n;i++)
 {
	 for(int j=0; j<n;j++)
	 {
		c[i][j]=0;
	 }
 }

 start_time = omp_get_wtime() ; // ïðåäñòàâëÿåò ñ÷åò÷èê òèêà
  for(int i=0;i<n;i++){
		for(j=0;j<n;j++){
			 sum=0;
			
			for(k=0;k<n;k++){
				 sum+=a[i][k]*b[k][j];
				 c[i][j]=sum;
			}
		}
	}

 end_time = omp_get_wtime() ;
 cout<<"Seq multiplication\n";
 cout<<"Time: "<<end_time-start_time<<" seconds"<<"\n";
 
	for(int i=0; i<n;i++)
	{
		delete a[i];
		delete b[i];
		delete c[i];
	}
	delete a;
	delete b;
	delete c;
	
    return 0;
	
}